package com.zscg.sequence.ui;

import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TabHost;
import android.widget.TabHost.OnTabChangeListener;
import android.widget.TextView;

import com.zscg.sequence.R;

public class SequenceTabActivity extends TabActivity implements OnTabChangeListener{

	private LayoutInflater mLayoutInflater;
	TabHost tabHost;
	TextView titleText;
	Button titleButton;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		
//		Intent intent = new Intent(this, SequenceService.class);
//		startService(intent);
		
		setContentView(R.layout.maintab);
		titleText = (TextView) findViewById(R.id.title_text);
		titleButton = (Button) findViewById(R.id.title_button);
		tabHost = getTabHost();
		mLayoutInflater = LayoutInflater.from(this);
		tabHost.addTab(tabHost.newTabSpec("message")
				.setContent(new Intent(SequenceTabActivity.this, MessageActivity.class))
				.setIndicator(newTabIndicator(R.drawable.tab_message,R.string.message)));
		tabHost.addTab(tabHost.newTabSpec("game")
				.setContent(new Intent(SequenceTabActivity.this, GameActivity.class))
				.setIndicator(newTabIndicator(R.drawable.tab_game,R.string.game)));
		tabHost.addTab(tabHost.newTabSpec("friend")
				.setContent(new Intent(SequenceTabActivity.this, FriendActivity.class))
				.setIndicator(newTabIndicator(R.drawable.tab_friend,R.string.friend)));
		tabHost.addTab(tabHost.newTabSpec("setting")
				.setContent(new Intent(SequenceTabActivity.this, SettingActivity.class))
				.setIndicator(newTabIndicator(R.drawable.tab_setting,R.string.setting)));
		
		 tabHost.setOnTabChangedListener(this);
		 tabHost.setCurrentTab(1);
		 
	}
	
	@Override
	public void onTabChanged(String tabId) {
		if("message".equalsIgnoreCase(tabId)){
			titleText.setText(R.string.message);
			titleButton.setVisibility(View.VISIBLE);
			titleButton.setText(R.string.add);
		}else if("game".equalsIgnoreCase(tabId)){
			titleText.setText(R.string.game);
			titleButton.setVisibility(View.GONE);
		}else if("friend".equalsIgnoreCase(tabId)){
			titleText.setText(R.string.friend);
			titleButton.setVisibility(View.VISIBLE);
			titleButton.setText(R.string.add);
		}else if("setting".equalsIgnoreCase(tabId)){
			titleText.setText(R.string.setting);
			titleButton.setVisibility(View.GONE);
		}
		
	}
	
	
	
	private View newTabIndicator(int tabIconResId, int tabTextResId) {
		View indicator = mLayoutInflater.inflate(R.layout.maintab_item,
				null);
		ImageView tabImg = (ImageView) indicator
				.findViewById(R.id.icon);
		tabImg.setImageResource(tabIconResId);
		TextView tabText = (TextView) indicator
				.findViewById(R.id.item_text);
		tabText.setText(tabTextResId);
		return indicator;
	}





}
